package com.yc.demo.servlet.login;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/home.s")
public class HomeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().append("这是主页<br>");
		HttpSession session = request.getSession();
		String loginedUser = (String) session.getAttribute("loginedUser");
		response.getWriter().append(session.getId()+"<br>");
		if (loginedUser == null) {
			// 1 没登录，  2. 会话过期
			response.getWriter().append("未登录<br>");
		} else {
			response.getWriter().append("欢迎"+loginedUser+"<br>");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
